// JavaScript Document
define(function (require, exports, module) {
	var SelectGroup=require("SelectGroup");
	var NumberInputGroup=require("NumberInputGroup");
	var IntInputGroup=require("IntInputGroup");
	var ChineseAmountGroup=require("ChineseAmountGroup");
	
	var HTMLTurbo=require("HTMLTurbo");

	Page = function(){
	};
	Page.prototype.baseInit=function(context){
		
		this.htmlTurbo=new HTMLTurbo();
		this.htmlTurbo.init(context);

		this.htmlTurbo.browserController.disabledBackspace();
		this.htmlTurbo.browserController.forwardLast();
		this.htmlTurbo.browserController.unSelectableDisabled();
		this.backAlert();
		
	}
	//读取选择框组
	Page.prototype.loadSelectGroupControl=function(options){
		var selectGroup=new SelectGroup(options);
		selectGroup.init();
		return selectGroup;
	}
	Page.prototype.getSelectGroupControl=function(options){
		var selectGroup=new SelectGroup(options);
		return selectGroup;
	}
	//获得数值输入组
	Page.prototype.getNumberInputGroupControl=function(minNumberInputSelector,maxNumberInputSelector){
		var numberInputGroup=new NumberInputGroup(minNumberInputSelector,maxNumberInputSelector);
		return numberInputGroup;
	}
	//获得数值输入组
	Page.prototype.getIntInputGroupControl=function(minIntInputSelector,maxIntInputSelector){
		var intInputGroup=new IntInputGroup(minIntInputSelector,maxIntInputSelector);
		return intInputGroup;
	}
	Page.prototype.getChineseAmountGroup=function(sourceElement,bindElement){
		var chineseAmountGroup=new ChineseAmountGroup(sourceElement,bindElement);
		return chineseAmountGroup;
	}
	Page.prototype.formActionNullHack=function(selector){
		var formAction=$(selector).attr("action");
		if(formAction==""){
			$(selector).attr("action","######")
		}
	}
	
	
	Page.prototype.initSelects=function(){
		var self=this;
		$("select").each(function(){
			self.setSelected(this)
		})
	}
	Page.prototype.setSelected=function(selector){
		var name=$(selector).attr("name")
		if(name=="province" || name=="city" || name=="county"){
			return ;
		}
		if(name=="regProvince" || name=="regCity" || name=="regCounty"){
			return ;
		}
		if(name=="creditorProvince" || name=="creditorCity" || name=="creditorCounty"){
			return ;
		}
		if(name=="debtorProvince" || name=="debtorCity" || name=="debtorCounty"){
			return ;
		}
		var options=$("option",selector)
		if(options.size()==1){
			return ;
		}
		var option=options.eq(0)
		var text=option.html()
		var value=option.attr("value")
		
		if(text==""){
			option.remove();
			$(selector).val(value);
		}
	}
	Page.prototype.backAlert=function(){
		if($("#backAlertMsg")&&$("#backAlertMsg").find("li").length>0){
			var liList=$("#backAlertMsg").find("li");
			var str="";
			for(var i=0;i<liList.length;i++){
				str+=liList.eq(i).html()+"\n";
			}
			alert(str);
		}
	}
	module.exports = Page;
});